<!DOCTYPE HTML>

<html>
    <head>
        <script type="application/ld+json">
    {
        "@context" : "http://schema.org",
        "@type" : "BlogPosting",
        "mainEntityOfPage": {
             "@type": "WebPage",
             "@id": "\/blog\/"
        },
        "articleSection" : "blog",
        "name" : "python数据类型常用方法",
        "headline" : "python数据类型常用方法",
        "description" : "mff的个人博客",
        "inLanguage" : "en",
        "author" : "",
        "creator" : "",
        "publisher": "",
        "accountablePerson" : "",
        "copyrightHolder" : "",
        "copyrightYear" : "2020",
        "datePublished": "2020-06-05 00:00:00 \x2b0000 UTC",
        "dateModified" : "2020-06-05 00:00:00 \x2b0000 UTC",
        "url" : "\/blog\/blog\/python%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95\/",
        "wordCount" : "188",
        "keywords" : [ "tutorial","Blog" ]
    }
    </script>
        
            
                <title>python数据类型常用方法</title>
            
        

        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="generator" content="Hugo 0.69.0" />
        
  
    
  

  

  <link rel="apple-touch-icon-precomposed" href='/blog/favicon/apple-touch-icon-precomposed.png'>
  <link rel="icon" href='/blog/favicon/favicon.png'>
  
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="msapplication-TileImage" content='/favicon/mstile.png'>
  <meta name="application-name" content="mff blog">
  <meta name="msapplication-tooltip" content="">
  <meta name="msapplication-config" content='/favicon/ieconfig.xml'>



        
            <meta name="author" content="mff">
        
        
            <meta name="description" content="mff的个人博客">
        

        <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="python数据类型常用方法"/>
<meta name="twitter:description" content="mff的个人博客"/>

        <meta property="og:title" content="python数据类型常用方法" />
<meta property="og:description" content="mff的个人博客" />
<meta property="og:type" content="article" />
<meta property="og:url" content="/blog/blog/python%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" />
<meta property="article:published_time" content="2020-06-05T00:00:00+00:00" />
<meta property="article:modified_time" content="2020-06-05T00:00:00+00:00" />

        <meta property="og:image" content="/blog//images/logo.png">
        <meta property="og:image:type" content="image/png">
        <meta property="og:image:width" content="512">
        <meta property="og:image:height" content="512">
        <meta itemprop="name" content="python数据类型常用方法">
<meta itemprop="description" content="mff的个人博客">
<meta itemprop="datePublished" content="2020-06-05T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2020-06-05T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="188">



<meta itemprop="keywords" content="tutorial," />
        

        
            
        

        
        
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-light.min.css">
            <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:400,800,900|Source+Sans+Pro:400,700">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.css">
            <link rel="stylesheet" href="/blog/css/main.css">
            <link rel="stylesheet" href="/blog/css/add-on.css">
            <link rel="stylesheet" href="/blog/css/academicons.min.css">
        

        
            
                
            
        


  
    
    <link href='//cdn.bootcss.com/highlight.js/9.11.0/styles/github.min.css' rel='stylesheet' type='text/css' />
  


      
    </head>
    <body>

      
      <div id="wrapper">

    
    
<header id="header">
    
      <h1><a href="/blog/">blog</a></h1>
    

    <nav class="links">
        <ul>
            
                <li>
                    <a href="/blog/">
                            <i class="fa fa-home">&nbsp;</i>主页
                    </a>
                </li>
            
                <li>
                    <a href="/blog/blog/">
                            <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                    </a>
                </li>
            
                <li>
                    <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                    </a>
                </li>
            
                <li>
                    <a href="/blog/itemized/">
                            <i class="fa fa-list">&nbsp;</i>最近项目
                    </a>
                </li>
            
                <li>
                    <a href="/blog/contact/">
                            <i class="fa fa-envelope-o">&nbsp;</i>联系我
                    </a>
                </li>
            
        </ul>
    </nav>
    <nav class="main">
        <ul>
            
            <li id="share-nav" class="share-menu" style="display:none;">
                <a class="fa-share-alt" href="#share-menu">Share</a>
            </li>
            
            <li class="search">
                <a class="fa-search" href="#search">Search</a>
                <form id="search" method="get" action="//google.com/search">
                    <input type="text" name="q" placeholder="Search" />
                    <input type="hidden" name="as_sitesearch" value="/blog/">
                </form>
            </li>
            <li class="menu">
                <a class="fa-bars" href="#menu">Menu</a>
            </li>
        </ul>
    </nav>
</header>


<section id="menu">

    
        <section>
            <form class="search" method="get" action="//google.com/search">
                <input type="text" name="q" placeholder="Search" />
                <input type="hidden" name="as_sitesearch" value="/blog/">
            </form>
        </section>

    
        <section>
            <ul class="links">
                
                    <li>
                        <a href="/blog/">
                            <h3>
                                <i class="fa fa-home">&nbsp;</i>主页
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/blog/">
                            <h3>
                                <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <h3>
                                <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/itemized/">
                            <h3>
                                <i class="fa fa-list">&nbsp;</i>最近项目
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/contact/">
                            <h3>
                                <i class="fa fa-envelope-o">&nbsp;</i>联系我
                            </h3>
                        </a>
                    </li>
                
            </ul>
        </section>

    
        <section class="recent-posts">
            <div class="mini-posts">
                <header>
                    <h3>Recent Posts</h3>
                </header>
                

                
                    
                

                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-08-27'>
                                    August 27, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-26'>
                                    July 26, 2020</time>
                            </header>
                            

                        </article>
                

                
                    <a href=
                        
                            /blog/
                        
                        class="button">View more posts</a>
                
            </div>
        </section>

    
        
</section>

    <section id="share-menu">
    <section id="social-share-nav">
        <ul class="links">
            <header>
                <h3>Share this post <i class="fa fa-smile-o"></i></h3>
            </header>
            



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;text=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;description=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


        </ul>
    </section>
</section>

    
    <div id="main">
        
        
        <article class="post">
  <header>
    <div class="title">
        
            <h1><a href="/blog/blog/python%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/">python数据类型常用方法</a></h1>
            
        
        
            <p>mff的个人博客</p>
        
    </div>
    <div class="meta">
        

        <time class="published"
            datetime='2020-06-05'>
            June 5, 2020</time>
        <span class="author">mff</span>
        
            <p>1 minute read</p>
        
        
    </div>
</header>


  
    <section id="social-share">
      <ul class="icons">
        



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;text=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;title=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f&amp;description=python%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2fpython%25E6%2595%25B0%25E6%258D%25AE%25E7%25B1%25BB%25E5%259E%258B%25E5%25B8%25B8%25E7%2594%25A8%25E6%2596%25B9%25E6%25B3%2595%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


      </ul>
    </section>
  

  

  <div id="content">
    <h2 id="列表的常用方法">列表的常用方法</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">a <span style="color:#f92672">=</span> [<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>]

<span style="color:#75715e"># 列表末尾追加新的对象</span>
a<span style="color:#f92672">.</span>append(<span style="color:#ae81ff">4</span>)

<span style="color:#75715e"># 统计列表内元素出现的次数</span>
b <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>count(<span style="color:#ae81ff">2</span>)

c <span style="color:#f92672">=</span> [<span style="color:#e6db74">&#39;a&#39;</span>,<span style="color:#e6db74">&#39;b&#39;</span>,<span style="color:#e6db74">&#39;c&#39;</span>]
d <span style="color:#f92672">=</span> [<span style="color:#e6db74">&#39;d&#39;</span>,<span style="color:#e6db74">&#39;e&#39;</span>,<span style="color:#e6db74">&#39;f&#39;</span>]
<span style="color:#75715e"># 在末尾追加多个元素</span>
c<span style="color:#f92672">.</span>extend(d)

<span style="color:#75715e"># 找出匹配到的第一个索引位置</span>
e <span style="color:#f92672">=</span> d<span style="color:#f92672">.</span>index(<span style="color:#e6db74">&#39;f&#39;</span>)

<span style="color:#75715e"># 根据索引位置插入</span>
d<span style="color:#f92672">.</span>insert(<span style="color:#ae81ff">2</span>,<span style="color:#e6db74">&#39;我是插入对象&#39;</span>)

<span style="color:#75715e"># 删除列表元素，默认是最后一个</span>
f <span style="color:#f92672">=</span> [<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">6</span>]

f<span style="color:#f92672">.</span>pop()
<span style="color:#75715e"># 指定索引删除</span>
f<span style="color:#f92672">.</span>pop(<span style="color:#ae81ff">4</span>)

<span style="color:#75715e"># 颠倒</span>
f<span style="color:#f92672">.</span>reverse()
<span style="color:#66d9ef">print</span>(f)
</code></pre></div><h2 id="字符串的常用方法">字符串的常用方法</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">a <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;abcdefg&#39;</span>

<span style="color:#75715e"># 查找字符串元素中的下标，没有就会返回-1</span>
b <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>find(<span style="color:#e6db74">&#39;h&#39;</span>)

<span style="color:#75715e"># 划出查找的索引区域</span>
c <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>find(<span style="color:#e6db74">&#39;a&#39;</span>,<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">3</span>)

<span style="color:#75715e"># 字符串拼接</span>
d <span style="color:#f92672">=</span> [<span style="color:#e6db74">&#39;你&#39;</span>,<span style="color:#e6db74">&#39;好&#39;</span>,<span style="color:#e6db74">&#39;呀&#39;</span>,<span style="color:#e6db74">&#39;!&#39;</span>]
e <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span><span style="color:#f92672">.</span>join(d)

<span style="color:#75715e"># 字符串切割,切完后为一个列表</span>
f <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;你好,呀!&#39;</span>

g <span style="color:#f92672">=</span> f<span style="color:#f92672">.</span>split(<span style="color:#e6db74">&#39;,&#39;</span>)

<span style="color:#75715e"># 字符串替换</span>
h <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;你好呀?&#39;</span>

i <span style="color:#f92672">=</span> h<span style="color:#f92672">.</span>replace(<span style="color:#e6db74">&#39;?&#39;</span>,<span style="color:#e6db74">&#39;!&#39;</span>)

<span style="color:#66d9ef">print</span>(i)
</code></pre></div><h2 id="字典常用方法">字典常用方法</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">a <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;a&#39;</span>:<span style="color:#e6db74">&#39;b&#39;</span>}

<span style="color:#75715e"># 清空字典</span>
a<span style="color:#f92672">.</span>clear()


<span style="color:#75715e"># 建立新的键，key为必须参数，value默认为None</span>
b <span style="color:#f92672">=</span> {}

c <span style="color:#f92672">=</span> b<span style="color:#f92672">.</span>fromkeys([<span style="color:#e6db74">&#39;name&#39;</span>,<span style="color:#e6db74">&#39;password&#39;</span>])

<span style="color:#75715e"># 获取键对应的值,获取不到返回None</span>
d <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;name&#39;</span>:<span style="color:#e6db74">&#39;mff&#39;</span>,<span style="color:#e6db74">&#39;password&#39;</span>:<span style="color:#e6db74">&#39;123&#39;</span>}

e <span style="color:#f92672">=</span> d<span style="color:#f92672">.</span>get(<span style="color:#e6db74">&#39;name&#39;</span>)

<span style="color:#75715e"># 修改键对应的值,搜索不到对应的键会默认添加进去,赋值的话会报错</span>
d<span style="color:#f92672">.</span>update({<span style="color:#e6db74">&#39;name&#39;</span>:<span style="color:#e6db74">&#39;mff1&#39;</span>,<span style="color:#e6db74">&#39;age&#39;</span>:<span style="color:#ae81ff">20</span>})

<span style="color:#66d9ef">print</span>(d)

<span style="color:#75715e"># 循环字典的方法</span>
<span style="color:#75715e"># 将key和value遍历出来</span>
<span style="color:#66d9ef">for</span> k,v <span style="color:#f92672">in</span> d<span style="color:#f92672">.</span>items():
    <span style="color:#66d9ef">print</span>(k,v)

<span style="color:#75715e"># 将key遍历出来</span>
<span style="color:#66d9ef">for</span> k <span style="color:#f92672">in</span> d<span style="color:#f92672">.</span>keys():
    <span style="color:#66d9ef">print</span>(k)

<span style="color:#75715e"># 将value便利出来</span>
<span style="color:#66d9ef">for</span> v <span style="color:#f92672">in</span> d<span style="color:#f92672">.</span>values():
    <span style="color:#66d9ef">print</span>(v)

<span style="color:#75715e"># 删除指定的键值对</span>
f <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;name&#39;</span>:<span style="color:#e6db74">&#39;mff&#39;</span>,<span style="color:#e6db74">&#39;password&#39;</span>:<span style="color:#e6db74">&#39;123&#39;</span>,<span style="color:#e6db74">&#39;age&#39;</span>:<span style="color:#ae81ff">18</span>}

f<span style="color:#f92672">.</span>pop(<span style="color:#e6db74">&#39;age&#39;</span>)

<span style="color:#66d9ef">print</span>(f)

<span style="color:#75715e"># 添加键对应的值</span>
g <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;name&#39;</span>:<span style="color:#e6db74">&#39;&#39;</span>,<span style="color:#e6db74">&#39;password&#39;</span>:<span style="color:#e6db74">&#39;&#39;</span>}

g[<span style="color:#e6db74">&#39;name&#39;</span>] <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;mff&#39;</span>
g[<span style="color:#e6db74">&#39;password&#39;</span>] <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;123&#39;</span>

<span style="color:#66d9ef">print</span>(g)
</code></pre></div><h2 id="集合的常用操作">集合的常用操作</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e"># 集合是一组key的集合，但不存储value，并且key不能重复</span>
set_list <span style="color:#f92672">=</span> [<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">6</span>,<span style="color:#ae81ff">1</span>]

<span style="color:#75715e"># 去重操作(当set去重以后才是一个集合)</span>
a <span style="color:#f92672">=</span> set(set_list)

<span style="color:#75715e"># 交集(将重复元素打印出来)</span>
set_list1 <span style="color:#f92672">=</span> set([<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">6</span>,<span style="color:#ae81ff">7</span>])

b <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>intersection(set_list1)

<span style="color:#75715e"># 并集(将所有元素打印出来，并且不打印重复元素)</span>
c <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>union(set_list1)

<span style="color:#75715e"># 差集</span>
<span style="color:#75715e"># 打印出a集合中set_list1中没有的元素</span>
d <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>difference(set_list1) 
<span style="color:#66d9ef">print</span>(d)
<span style="color:#75715e"># 打印出set_list1集合中a中没有的元素</span>
e <span style="color:#f92672">=</span> set_list1<span style="color:#f92672">.</span>difference(a)
<span style="color:#66d9ef">print</span>(e)
</code></pre></div>
  </div>

  <footer>
    <ul class="stats">
  <li class="categories">
    <ul>
        
            
            
                <i class="fa fa-folder"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/categories/hugo">Hugo</a></li>
                
            
        
    </ul>
  </li>
  <li class="tags">
    <ul>
        
            
            
                <i class="fa fa-tags"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/tags/tutorial">tutorial</a></li>
                
            
        
    </ul>
  </li>
</ul>

  </footer>

</article>

    <article class="post">
        <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "shortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
    </article>


<ul class="actions pagination">
    
        <li><a href="/blog/blog/%E9%82%AE%E7%AE%B1%E6%BF%80%E6%B4%BB/"
                class="button big previous">邮箱激活</a></li>
    

    
        <li><a href="/blog/blog/%E6%89%93%E5%8D%A1%E7%B3%BB%E7%BB%9F%E6%8A%80%E6%9C%AF%E6%80%BB%E7%BB%93%E5%88%86%E6%9E%90/"
                class="button big next">打卡系统技术总结分析</a></li>
    
</ul>


    </div>
    
<section id="sidebar">

  
  <section id="intro">
    
    
      
        <a href='/blog/'><img src="/blog/img/main/touxiang3.jpg" class="intro-circle" width="150px" alt="Hugo Future Imperfect" /></a>
      
    
    
      <header>
        <h2>mff</h2>
        <p>Effort is for money, and money is life!</p>
      </header>
    
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
  </section>

  
  <section class="recent-posts">
    <div class="mini-posts">
      <header>
        <h3>Recent Posts</h3>
      </header>
      <div class="posts-container">
        

        
          
        

        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a>
              </h3>
              
              <time class="published" datetime='2020-08-27'>
                August 27, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a>
              </h3>
              
              <time class="published" datetime='2020-07-26'>
                July 26, 2020
              </time>
            </header>
            

          </article>
        
      </div>

      
        <a href=
          
            /blog/
          
        class="button">View more posts</a>
      
    </div>
  </section>

  
  
  
  
  
    <section id="categories">
      <header>
        <h3>
          <a href="/blog/categories/">Categories</a>
        </h3>
      </header>
        
          
        

        
        <p>
          <article>
            <header>
              
                <a href="/blog/categories/hugo/">hugo</a>
                <span style="float:right;">43</span>
              
            </header>
          </article>
        </p>
        
    </section>
  
  

  
  
    <section id="mini-bio">
      <h3>About</h3>
      <p>blog于2018年6月10日创建(It was created on May 10, 2020),文章主要介绍了python的一些常用框架和库及它们的一些用法</p>
      <a href="/blog/about/" class="button">Learn More</a>
    </section>
  

  
  <section id="footer">
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
    <p class="copyright">
      
        &copy; 2020
        
          mff blog
        
      .
      Powered by <a href="//gohugo.io" target="_blank">Hugo</a>
    </p>
  </section>
</section>

    </div>
    <a id="back-to-top" href="#" class="fa fa-arrow-up fa-border fa-2x"></a>
    

    
      
    

    
      
      
      
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/highlight.min.js"></script>
        
        
        
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/r.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/yaml.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/css.min.js"></script>
        <script>hljs.configure({languages: []}); hljs.initHighlightingOnLoad();</script>
      
    
    
    
      <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/skel/3.0.1/skel.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.js"></script>
      <script src="/blog/js/util.js"></script>
      <script src="/blog/js/main.js"></script>
      <script src="/blog/js/backToTop.js"></script>
    

    
      
        
      
    

    
    <script>hljs.initHighlightingOnLoad();</script>
      <script src="//yihui.name/js/math-code.js"></script>
<script async
src="//cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>


  </body>
</html>

